<template>
  <div class="news-box">
    <virtual-scroll
      :msg="msg"
      :oneHeight="oneHeight"
      :requestUrl="requestUrl"
      :requestNum="requestNum"
      :moreRquestNum="moreRequestNum"
    >
      <template v-slot="{ item }">
        <router-link
          class="one-new"
          :to="
            '/article/' +
            item.title +
            '/' +
            item.reads +
            '/' +
            item.from +
            '/' +
            item.date +
            '/' +
            item.image
          "
        >
          <!-- 新闻左侧标题、评论、来源部分 -->
          <div class="new-left">
            <h3>{{ item.title }}</h3>
            <div>
              <p>
                <img src="../assets/icons/msg.png" alt="评" />
                <span>{{ item.reads }}</span>
                <span>{{ item.from }}</span>
              </p>
              <h4>{{ item.date }}</h4>
            </div>
          </div>
          <!-- 新闻右侧图片部分 -->
          <div class="new-right">
            <img :src="imgsList[item.image]" alt="PIC" />
          </div>
        </router-link>
      </template>
    </virtual-scroll>
  </div>
</template>

<script>
// 引入准备好的新闻图片相关信息
import imgsList from "../components/newsImgs.js";

export default {
  name: "index",
  data() {
    return {
      // 图片数组
      imgsList,
      // 提示信息
      msg: "小二正在努力，请耐心等待...",
      //单条新闻的高度
      oneHeight: 100,
      //数据来源 URL
      requestUrl: "http://192.168.43.168:4000/data?num=",
      //第一次请求数据的条数
      requestNum: 20,
      //下拉触底时请求数据的条数
      moreRequestNum: 20,
    };
  },
};
</script>

<style lang="scss" scoped>
.news-box {
  width: 100%;
  max-width: 800px;
  height: 100%;
  .one-new {
    text-decoration: none;
    display: block;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    border-bottom: 1px solid #ddd;
    padding: 14px 10px 5px;
    .new-left {
      height: 80px;
      position: relative;
      h3 {
        padding: 0;
        margin: 0;
        font-size: 16px;
        text-align: justify;
        color: #555;
      }
      div {
        position: absolute;
        width: 100%;
        bottom: 10px;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: space-between;
        align-items: center;
        p {
          display: flex;
          flex-direction: row;
          flex-wrap: nowrap;
          justify-content: space-between;
          align-items: center;
          img {
            height: 16px;
          }
          span {
            font-size: 12px;
            color: #555;
            margin-left: 3px;
            margin-right: 3px;
          }
        }
        h4 {
          font-size: 12px;
          color: #888;
        }
      }
    }
    .new-right {
      margin-left: 10px;
      img {
        height: 68px;
      }
    }
  }
}
</style>
